package cn.cxj.basic.controller;

import cn.cxj.basic.exception.BusinessException;
import cn.cxj.basic.service.IVerifyCodeService;
import cn.cxj.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 验证码接口
 * @author chenxinjie
 * @date 2022-2-5 16:49:59
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 发送短信验证码
     * @param params
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String, String> params){
        try {
            verifyCodeService.sendSmsCode(params);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("网络繁忙,请稍后重试!");
        }


    }
}
